package com.share.demo.event;

import lombok.extern.slf4j.Slf4j;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

/**
 * author:caifan
 * date:2019/12/16
 */
@Slf4j
public class WatcherA implements Watcher {

    private ZooKeeper zookeeper;

    private String watchPath;

    public WatcherA(ZooKeeper zookeeper, String watchPath) {
        this.zookeeper = zookeeper;
        this.watchPath = watchPath;
    }

    @Override
    public void process(WatchedEvent event) {
        try {
            zookeeper.exists(watchPath, this);
            log.info("path:{}", event.getPath());
            log.info("type:{}", event.getType());
        } catch (Exception e) {
            log.error("error:{}", e.getMessage());
        }
    }
}
